/**
 * 跳转到指定页面（主要是为了补前/，同时简化一些操作）
 * @param url
 * @param options
 */
export const toPage = (url, options = {}) => {
  if (!url) return;
  if (!url.startsWith('/')) {
    url = '/' + url;
  }
  console.log(url);
  return uni.navigateTo({
    url,
    ...options,
  });
};

export const goBack = (options) => {
  uni.navigateBack({
    delta: 1,
    success: (res) => {
      uni.$emit('back', options);
    },
  });
};

export const showToast = (title = '异常错误', duration = 2000, mask = false, icon = 'none') => {
  //#ifdef MP-WEIXIN
  wx.showToast({
    title,
    duration,
    mask,
    icon,
  });
  //#endif
  //#ifndef MP-WEIXIN
  uni.showToast({
    title,
    duration,
    mask,
    icon,
  });
  //#endif
};

export const showLoading = (title, mask = true) => {
  //#ifdef MP-WEIXIN
  wx.showLoading({
    title,
    mask,
  });
  //#endif
  //#ifndef MP-WEIXIN
  uni.showLoading({
    title,
    mask,
  });
  //#endif
};

export const hideLoading = () => {
  //#ifdef MP-WEIXIN
  wx.hideLoading();
  //#endif
  //#ifndef MP-WEIXIN
  uni.hideLoading();
  //#endif
};
